import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
import { modelBaseUrl } from '@/setting';
import { notification } from 'ant-design-vue';
import { IndiResponseBody } from '@/api/typing';
const service = axios.create({
  baseURL: modelBaseUrl,
  timeout: 30000,
  withCredentials: false,
  headers: { 'X-Requested-With': 'XMLHttpRequest' },
});

// 请求拦截器
const requestHandler = (
  config: AxiosRequestConfig,
): AxiosRequestConfig | Promise<AxiosRequestConfig> => {
  config.headers['Access-Control-Allow-Origin'] = '*';
  return config;
};

// 响应拦截器
const responseHandler = (
  response: AxiosResponse,
): IndiResponseBody | AxiosResponse | Promise<any> | any => {
  const { data: { code, msg } } = response;
  response.data.success = true
  if (code !== '0x00000000') {
    response.data.success = false
    notification.warning({ message: '⚠️指标系统响应警告', description: msg, duration: 4, });
  }
  return response.data;
};
service.interceptors.request.use(requestHandler);
service.interceptors.response.use(responseHandler);
export default service;

